//
//  WelcomeViewController.m
//  weibo110
//
//  Created by 臧松 on 15/12/29.
//  Copyright © 2015年 臧松. All rights reserved.
//

#import "WelcomeViewController.h"
#import "UILabel+Extension.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "UserAccountViewModel.h"
@interface WelcomeViewController ()
// 启动图片
@property (nonatomic,strong) UIImageView * backImageView;

// 头像
@property (nonatomic,strong) UIImageView * iconView;

// 欢迎标签
@property (nonatomic,strong) UILabel * welcomLabel;


@end

@implementation WelcomeViewController
-(UIImageView *)iconView{
    if (_iconView == nil) {
        
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
        
        _iconView.layer.cornerRadius = 45;
        _iconView.layer.masksToBounds = YES;
    }
    return _iconView;
}
-(UILabel *)welcomLabel{
    if (_welcomLabel == nil) {
        
        _welcomLabel = [UILabel labelWithTitle:@"欢迎归来" fontSize:18 color:[UIColor darkGrayColor] screenInset:0];
        
    }
    return _welcomLabel;
}
-(UIImageView *)backImageView{
    if (_backImageView == nil) {
        
        _backImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ad_background"]];
        
    }
    return _backImageView;
}
-(void)loadView{

    self.view = self.backImageView;
    
    [self setupUI];
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    [self.iconView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.view.mas_bottom).offset(-self.view.bounds.size.height + 200);
    }];
    self.welcomLabel.alpha = 0.0;
    
    [UIView animateWithDuration:1.2 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:10 options:UIViewAnimationOptionLayoutSubviews animations:^{
        
        [self.view layoutIfNeeded];
        
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.5 animations:^{
            
            self.welcomLabel.alpha = 1.0;
            
        } completion:^(BOOL finished) {
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"WBRootViewController" object:nil userInfo:nil];
            NSLog(@"ok");
        }];
    }];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   [self.iconView sd_setImageWithURL:[UserAccountViewModel shareUserAccount].avatar placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
}

-(void)setupUI{
    // 添加控件
    [self.view addSubview: self.welcomLabel];
    [self.view addSubview:self.iconView];

    // 自动布局
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view.mas_centerX);
        make.bottom.equalTo (self.view.mas_bottom).offset(-200);
        make.height.equalTo(@90);
        make.width.equalTo(@90);
        
    }];
    [self.welcomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(self.iconView.mas_bottom).offset(16);
        
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
